package com.onlyphoto.onlymall.mvp.presenter

import android.content.Context
import com.onlyphoto.onlymall.base.BaseEntity
import com.onlyphoto.onlymall.base.BaseNetworkResponse
import com.onlyphoto.onlymall.base.BaseObserver

import com.onlyphoto.onlymall.mvp.contract.CGoodsDetails
import com.onlyphoto.onlymall.mvp.model.MGoodsDetailsImpl
import com.onlyphoto.onlymall.base.BasePresenter
import com.onlyphoto.onlymall.bean.request.CartGoodsBean
import com.onlyphoto.onlymall.bean.response.GoodsDetailsBean


class PGoodsDetailsImpl(mContext: Context, mView: CGoodsDetails.IVGoodsDetails) : BasePresenter<CGoodsDetails.IVGoodsDetails, MGoodsDetailsImpl>(mContext, mView, MGoodsDetailsImpl()), CGoodsDetails.IPGoodsDetails {
    override fun getDetails(id: Int) {
        mModel.requestDetails(object :BaseObserver<GoodsDetailsBean>(mContext.get()){
            override fun onSuccess(data: GoodsDetailsBean?, msg: String?) {
                if (data == null) {
                    mView.showEmpty()
                }
                mView.getDetailsSuccess(data!!)
            }

            override fun onCodeError(t: BaseNetworkResponse<GoodsDetailsBean>?) {
            }

            override fun onFailure(e: Throwable?) {
            }

            override fun onRequestStart() {
                mView.showLoading()
            }

            override fun onFinally() {
                mView.hideLoading()
            }

        }, id)
    }

    override fun add2Cart(bean: CartGoodsBean) {
        mModel.add2Cart(object :BaseObserver<BaseEntity>(mContext.get()){
            override fun onSuccess(data: BaseEntity?, msg: String?) {
                mView.add2CartSuccess()
            }

            override fun onCodeError(t: BaseNetworkResponse<BaseEntity>?) {
            }

            override fun onFailure(e: Throwable?) {
            }

            override fun onRequestStart() {
            }

            override fun onFinally() {
            }

        }, bean)
    }
}
